<%@ page language="java" pageEncoding="UTF-8" buffer="16kb"%>
<%@ include file="/base.jsp"%>
<%@ include file="/module/taglibs.jsp"%>
<%@ include file="/module/nocache.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>校本培训管理编辑页面</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<%@ include file="/module/js.jsp"%>
<%@ include file="/module/orderField.jsp"%>
	<script type="text/javascript" src="${basePath}/js/jquery.Huploadify.js"></script>
	<link href="${basePath}/css/Huploadify.css" rel="stylesheet">
<style type="text/css">
	
	     .grid{font:12px arial,helvetica,sans-serif;border:1px solid #cccccc}
        .grid td{font:100% arial,helvetica,sans-serif;height:24px;padding:5px}
        .grid{width:100%;border-collapse:collapse}.grid th{background:#eeeeee;height:27px;line-height:27px;border:1px solid #cccccc;padding-left:5px}
        .grid td{border:1px solid #cccccc;padding-left:5px;text-align: center;}

        .list * {
            margin: 0;
            padding: 0;
            outline: none;
            list-style: none;
            box-sizing: border-box;
        }

        .list li {

            overflow: hidden;
            padding: 20px;
            border-bottom: 1px solid #efefef;
        }

        .list .list_left {
            float: left;
        }

        .list .list_right {
            float: right;
        }

        .list .list_content {
            padding-left: 200px;
            padding-right: 200px;
        }

        .list_pagination {
            padding: 20px;
            text-align: right;
            font-size: 0;
        }

        .list_pagination span {
            cursor: pointer;
            display: inline-block;
            vertical-align: middle;
            font-size: 14px;
            border: 1px solid #dfdfdf;
            min-width: 30px;
            padding: 0 10px;
            color: #333;
            height: 30px;
            font-weight: bold;
            line-height: 30px;
            text-align: center;
            background-color: #F5F4F4;
            margin-right: 10px;
        }

        .list_pagination span.is-selected {
            background-color: #34383A;
            color: #fff;
        }
        .list_pagination span.is-disabled {
            /*background-color: #34383A;*/
            color: #ccc;
            pointer-events: none;
            cursor: not-allowed;
        }
        .list_pagination span.is-ellipsis{
            border: 0;
            background-color: transparent;
        }
	</style>
	<script type="text/javascript">
	
	//计算两个时间中间的年月
    function getYearAndMonth(staYear, endYear) {
        var result = [];
        while (staYear <= endYear) {
        	 result.push(staYear);
        	 staYear++;
        }
        return result;
    }
	
        //图片上传
        var file_path = "prefix";
        var file_path_one = null;
        var fileMap = new Array();
        $(function(){
        	//默认添加当时系统时间的年份，可手动修改，大于等于2010小于等于2099的正整数
        	var myDate = new Date();
    		var year = myDate.getFullYear();
        	var arrp = getYearAndMonth('2010','2099');
        	var _options = '';
        	for (var i = 0; i < arrp.length; i++) {
				var val = arrp[i];
				if(val == year){
					_options = _options + "<option selected='selected' value="+val+">" + val + "年</option>";
				}else{
					_options = _options + "<option value="+val+">" + val + "年</option>";
				}
				
			}
			$("#pxNd").html(_options);
        	
            var up = $('#uploadadd').Huploadify({
                auto:false,
                fileTypeExts:'*.*',
                multi:true,
                formData:{key:123456,key2:'vvvv'},
                fileSizeLimit:99999999999,
                showUploadedPercent:true,
                showUploadedSize:true,
                removeTimeout:9999999,
                uploader : '${basePath}/schoolTraining/source_upload',
                onUploadStart:function(file){
                    console.log(file.name+'开始上传');
                },
                onInit:function(obj){
                    console.log('初始化');
                    console.log(obj);
                },
                onUploadComplete:function(file,data){
                    debugger;
                    var fi = $.parseJSON(data);
                    //文件名称
                    var filename = fi.filename;
                    //生成后的文件名
                    var sysFilepath = fi.sysfilepath;
                    //文件路径
                    var filepath = fi.filepath;
                    file_path_one = filename + "," + filepath;
                    file_path = file_path+"|"+filepath;
                    up.filePath=file_path_one;
                    //保存到集合
                    fileMap[file.index]=new Array(file_path_one);
                },
                onCancel:function(file){
                    console.log(file.name+'删除成功');
                },
                onClearQueue:function(queueItemCount){
                    console.log('有'+queueItemCount+'个文件被删除了');
                },
                onDestroy:function(){
                    console.log('destroyed!');
                },
                onSelect:function(file){
                    console.log(file.name+'加入上传队列');
                },
                onQueueComplete:function(queueData){
                    console.log('队列中的文件全部上传完成',queueData);
                }
            });
        });

        //删除图片
        function deletefile(id){
            var url = "${basePath}/schoolTraining/deletefile";
            $.ajax({
                type : "POST",
                url : url,
                dataType:"json",
                data:{
                    filepath : id
                },
                success : function(data) {
                    if(data.success == "0000"){
                        alert("删除数据成功！");
                        var file_name = id.split(",")[0];
                        $("#"+file_name+"_hr").parent().parent().remove();
                    }else{
                        alert("未写入数据库的文件没有删除！请联系管理员！");
                    }
                }
            })
        }
	</script>

<script>
		$(document).ready(function() {
			
			  var json_dy_info = new Array();
			  json_dy_info = JSON.parse('${json}');
			  var pxId = '${entity.pxId}';
			  
			  var data_qingjia_update = new Array();
			  if(pxId != 0 && pxId != null){
				  qingjia_update = JSON.parse('${plistJson}');
				  if(qingjia_update!=null && qingjia_update.length>0){
	                  drawTable("tpl_dy_shouxun","dy_shouxun_list_info_id",qingjia_update);
	              }
			  }
			  
              var data_shouxun = [];
              
			$("#div1").dialog({
				width : 'auto',
				height : 'auto',
				bgiframe : true,
				modal : true,
				draggable : true,
				resizable : false,
				title : '选择职工',
				autoOpen : false,
				buttons : {
					'取消' : function() {
						$(this).dialog('close');
					},
					'确定' : function() {
						var wyxm_id = '';
						
						  var data = [];
                          var selected_item = document.getElementById("toSelect1");
   
                          if(selected_item.length==null || selected_item.length==0){
                              alert("请选择一项");
                              return false;
                          }
                          
                          for(var i=0;i<selected_item.length;i++){
                              var empId = selected_item.options[i].value;
                              for(var j=0;j<json_dy_info.length;j++){
                                  if(empId==json_dy_info[j].empId){
                                	  wyxm_id += json_dy_info[j].empId + ',';
                                      data.push({//往对象的末尾添加一个对象
                                    	  empId: json_dy_info[j].empId,
                                    	  empXm: json_dy_info[j].empXm,
                                          zgh: json_dy_info[j].zgh,
                                          ksMc: json_dy_info[j].ksMc,
                                          jyzMc: json_dy_info[j].jyzMc
                                      });
                                  }
                              }
                          }
                          
                          data_shouxun = getTargetJSON(data,data_shouxun);
                          drawTable("tpl_dy_shouxun","dy_shouxun_list_info_id",data_shouxun);
                          
                          //保存职工Id
                          $("#zdyRy_id").val(wyxm_id);
                         // alert($("#zdyRy_id").val());
						$(this).dialog('close');
					}

				}
			});
			
			
			 $("#delSelect1").click(function(){
                 var iii = $.getSelectIds('dyItems1');
                 if(iii.length==0){
                     alert('请至少选择一项删除');
                     return false;
                 }
                 $("input:checkbox[name='dyItems1']:checked").each(function() {
                     removeObjFromJSON($(this).val(),data_shouxun);
                 });
                 drawTable("tpl_dy_shouxun","dy_shouxun_list_info_id",data_shouxun);
             });

             $.select2("selectall1","dyItems1");

		});
		function showdiv() {
			$('#div1').dialog('open');
		}

		  //判断是否已经存在该元素值
        function getTargetJSON(fromJSON,toJSON){
            if(toJSON==null || toJSON.length==0){
                toJSON = fromJSON;
            }else{
                for(var i=0;i<fromJSON.length;i++){
                    var empId = fromJSON[i].empId;
                    var isExist = 0;
                    for(var j=0;j<toJSON.length;j++){
                        if(empId==toJSON[j].empId){
                            isExist=1;
                        }
                    }
                    if(isExist==0){
                        toJSON.push(fromJSON[i]);
                    }
                }
            }
            return toJSON;
        }

        //从JSON中移除某个对象
        function removeObjFromJSON(empId,targetJSON) {
            for(var i=0;i<targetJSON.length;i++){
                if(targetJSON[i].empId == empId) {
                    targetJSON.splice(i,1);
                }
            }
        }

        //输出表格数据
        function drawTable(tplId,table_id,data) {
            $("#"+table_id).html('');
            for(var k=0;k<data.length;k++){
                data[k].iindex = k;
                var html = template(tplId,data[k]);
                $("#"+table_id).html($("#"+table_id).html()+html);
            }
        }
	</script>
</head>
<body>
	<form action="#" name="Form" id="Form" method="post">
		<input  type="hidden" id="pxId" name="pxId"  value="${entity.pxId }"/>
		<input  type="hidden" id="urlTp" name="urlTp"  value=""/>
		<input type="hidden" id="zdyRy_id" name="zdyRy_id" value="${zdyRy_id }" />
		<table cellpadding="0" cellspacing="0" border="0" class="table-border" width="95%">
			<tr>
				<td class="table-header" colspan="4">校本培训信息</td>
			</tr>
			<tr>
				<td class="table-titleTD" style="width:15%;"><font
						style="color: red;">*</font>项目名称：</td>
				<td class="table-contentTD" style="width:35%;">
					<input id="xmmc" name="xmmc"  placeholder="项目名称"  autocomplete="off" maxlength="100" class="inputText required"  value="${entity. xmmc}"/></td>
					<td class="table-titleTD"><font
						style="color: red;">*</font>年度：</td>
				<td class="table-contentTD">
						<select id="pxNd" name="pxNd" class="selectList">
						</select>
					</td>
			</tr>
			<tr>
				<td class="table-titleTD"><font
						style="color: red;">*</font>学分：</td>
				<td class="table-contentTD" >
					<input id="xf" name="xf"  placeholder="学分"  autocomplete="off" maxlength="100" class="inputText required number"    value="${entity. xf}"/></td>
					
					<td class="table-titleTD"><font
						style="color: red;">*</font>年度学分小计：</td>
				<td class="table-contentTD" >
					<input id="ndxfXj" name="ndxfXj"  placeholder="年度学分小计"  autocomplete="off" maxlength="100" class="inputText required number"  value="${entity. ndxfXj}"/></td>
			</tr>
			<%--<c:if test="${ entity.pxId != 0  }">--%>
				<tr>
					<td class="table-titleTD">创建人：</td>
					<td class="table-contentTD">
						${entity.creatorName}
					</td>
					<td class="table-titleTD">创建日期：</td>
					<td class="table-contentTD">
						${entity.createTime}
					</td>
				</tr>
			<%--</c:if>--%>
			<tr>
				<td class="table-titleTD">附件：</td>
				<td class="table-contentTD" colspan="3">
					<table>
						<tr>
							<td colspan="2">
								<div id="uploadadd"></div>
							</td>
						</tr>
						<c:if test="${fn:length(dataList) > 0}">
							<c:forEach items="${dataList}" var="datalist" varStatus="index">
								<tr>
									<td>
										[文件] ${datalist.fileName}
									</td>
									<td>
										<a href="${basePath}/DownLoadFileServlet?filename=${datalist.fileName}&filepath=${datalist.filePath}">下载</a>
										
										<%-- <button type="button"  onclick="window.location.href='${basePath}/DownLoadFileServlet?filename=${datalist.fileName}&filepath=${datalist.filePath}'">下载</button> --%>
										&nbsp;&nbsp;
										
										<button id="${datalist.fileId}_hr" type="button"  onclick="deleteByPK('${datalist.fileId}','${datalist.filePath}');">删除</button>
									</td>
								</tr>
							</c:forEach>
						</c:if>
					</table>
				</td>
			</tr>
			<tr>
				<td class="table-titleTD">内容：</td>
				<td class="table-contentTD" colspan="3">
					<textarea rows="15" cols="60" name="remark" id="remark" maxlength="2000" >${entity.remark }</textarea>
				</td>
			</tr>
			
			<!--   增加左右选中人员效果 -->
			<tr>
                    <td class="table-titleTD">拟受训人员：</td>
                    <td class="table-contentTD" colspan="3">
                        <input type="button" id="btnSelect1" value="选择"
                               class="inputButton" onclick="javascript:showdiv();"/>
                        <input type="button" id="delSelect1" value="删除"
                               class="inputButton"/>
                    </td>
                </tr>
                <tr>
                    <td colspan="4">
                        <table class="grid" id="tb_dy_qingjia_id">
                            <thead>
                            <tr>
                                <th><input type="checkbox" name="selectall1" id="selectall1" /></th>
                                <th>序号</th>
                                <th>姓名</th>
                                <th>工号</th>
                                <th>部门</th>
                                <th>教研组</th>
                            </tr>
                            </thead>
                            <tbody id="dy_shouxun_list_info_id">

                            </tbody>
                        </table>
                    </td>
                </tr>
                
			
		</table>
	</form>
	
	<div id="div1" style="display: none;">
		<table cellpadding="0" cellspacing="0" border="0" class="table-border">
			<tr>
				<td style="clear: both; width: 45%"><input class="text"
					name="searchemp"
					ondblclick="javascript:filterSelectItems('sourseFromSelect1','fromSelect1','toSelect1',this.value);"
					onkeyup="javascript:filterSelectItems('sourseFromSelect1','fromSelect1','toSelect1',this.value);" /><font
					color="green">在此查找</font> <br /> <br /> <label
					style="color: red;">未选中:</label><br /> 
					
					<select name="fromSelect1"
						id="fromSelect1" multiple="multiple"
						style="width: 400px; height: 300px;"
						ondblclick="moveField('fromSelect1','toSelect1');">
						<c:forEach items="${employees}" var="data">
							<option value="${data.empId}">${data.empXm}</option>
						</c:forEach>
				</select> 
				
				<select name="sourseFromSelect1" id="sourseFromSelect1"
					multiple="multiple"
					style="width: 400px; height: 300px; display: none;"
					ondblclick="moveField('fromSelect1','toSelect1');">
					
					<c:choose>
							<c:when test="${ entity.pxId == 0  }">
									<c:forEach items="${employees}" var="data">
										<option value="${data.empId }">${data.empXm }</option>
									</c:forEach>
							</c:when>
							<c:otherwise>
								<c:forEach items="${plist}" var="data2">
									<c:forEach items="${employees}" var="data">
										<c:choose>
											<c:when test="${data2.empId == data.empId }">
											</c:when>
											<c:otherwise>
												<option value="${data.empId}">${data.empXm}</option>
											</c:otherwise>
										</c:choose>
									</c:forEach>
								</c:forEach>
							</c:otherwise>
					</c:choose>
					
						
				</select></td>
				<td align="center" style="width: 10%"><input type="button"
					onclick="moveAllField('fromSelect1','toSelect1');"
					style="width: 50px;" value=">>" /> <br> <br /> <input
						type="button" onclick="moveField('fromSelect1','toSelect1');"
						style="width: 50px;" value=">" /> <br /> <br /> <input
						type="button" style="width: 50px;" value="&lt"
						onclick="moveField('toSelect1','fromSelect1');" /><br /> <br />
						<input type="button" style="width: 50px;"
						onclick="moveAllField('toSelect1','fromSelect1');" value="&lt&lt" /></td>
				<td style="width: 45%"><br /> <label style="color: red;">已选中:</label><br />
					
					<select name="toSelect1" id="toSelect1" multiple="multiple"
					class="text" style="width: 400px; height: 300px;"
					ondblclick="moveField('toSelect1','fromSelect1');">
						<c:forEach items="${plist}" var="data2">
							<option value="${data2.empId}">${data2.empXm}</option>
						</c:forEach>
				</select>
				</td>
			</tr>
		</table>
	</div>
	
	<script id="tpl_dy_shouxun" type="text/html">
        <tr id="tr_qingjia_{{empId}}">
            <td>&nbsp;<input type="checkbox" name="dyItems1" value="{{empId}}"/></td>
            <td>{{iindex+1}}</td>
            <td>{{empXm}}</td>
            <td>{{zgh}}</td>
            <td>{{ksMc}}</td>
            <td>{{jyzMc}}</td>
        </tr>
    </script>
	
	<br />
	
	<c:choose>
		<c:when test="${ entity.pxId == 0 }">
			<table cellpadding="1" cellspacing="1" border="0" align="left">
			<tr>
				<%-- <kl:permission permisstionList="${permisstionList}" currentUser="${_login_console_user}" currentCatalogId="<%=CatalogUtils.getCatalogId("ZHDJ_DJZX_DJZX")%>" key="add"> --%>		
				    <td><input type="button" id="btnSave2Info" class="inputButton" style="text-align: center;" value="保存" /></td>
					<td><input type="button" id="btnSave2AddInint" class="inputButton" style="text-align: center;" value="保存并新增" /></td>
			    <%-- </kl:permission> --%>
				<td><input type="button" id="Cancel1" class="inputButton" style="text-align: center;" value="取消"  onclick="cancle()"/></td>
				<td><input type="button" id="returnBut1" class="inputButton" value="返回" style="text-align: center;" onclick="back2Index()"/></td>
			</tr>
		 </table>
		</c:when>
		<c:otherwise>
			<table cellpadding="1" cellspacing="1" border="0" align="left">
			<tr>
				 <%-- <kl:permission permisstionList="${permisstionList}" currentUser="${_login_console_user}" currentCatalogId="<%=CatalogUtils.getCatalogId("ZHDJ_DJZX_DJZX")%>" key="modify"> --%>		
				    <td><input type="button" id="btnSave2Index" class="inputButton" style="text-align: center;" value="保存" /></td>
				 <%-- </kl:permission> --%>
				<td><input type="button" id="Cancel2" class="inputButton" style="text-align: center;" value="取消" onclick="cancle()"/></td>
				<td><input type="button" id="returnBut2" class="inputButton" value="返回" style="text-align: center;" onclick="back2Index()" /></td>
			</tr>
		</table>
		</c:otherwise>
	</c:choose>
	
	<script>
		$(document).ready(function() {
			
			//保存成功返回详情页面
			$("#btnSave2Info").click(function() {
				var _form=$("#Form").validate();
				if(_form.form()){
					$("#urlTp").attr("value",1);
					document.Form.action ="${basePath}/schoolTraining/save";
					document.Form.submit();
				}
			});
			
			//保存成功继续增加页面
			$("#btnSave2AddInint").click(function() {
				var _form=$("#Form").validate();
				if(_form.form()){
					$("#urlTp").attr("value",2);
					document.Form.action ="${basePath}/schoolTraining/save";
					document.Form.submit();
				}
			});
			
			
			//保存成功返回列表页面
			$("#btnSave2Index").click(function() {
				var _form=$("#Form").validate();
				if(_form.form()){
					$("#urlTp").attr("value",3);
					document.Form.action ="${basePath}/schoolTraining/save";
					document.Form.submit();
				}
			});
			
		});
		
		
		//取消->当前页面刷新
		function cancle(){
			window.location.reload();//刷新当前页面.
		}
		
		//返回列表页面
		function back2Index(){
			window.location.href='${basePath}/schoolTraining/index';
		}
		
		//已有的数据进行删除操作
		function deleteByPK(id,filePath){
			var action = "${basePath}/schoolTraining/source_upload_update";
		    layer.confirm("您是否删除当前选中数据信息", {icon: 3, title:'提示',skin:'layer-ext-moon'}, function(index){
					$.ajax({
						type : "POST",
						url : action,
						//dataType:"json",
						data:{
							fileId : id,
							filePath : filePath
						},
						success : function(data) {
							if(data.success == "0000"){
								layer.alert('删除数据成功', {icon: 6});
								$("#"+id+"_hr").parent().parent().remove();
							}else{
								layer.alert('未写入数据库的文件没有删除！请联系管理员！', {icon: 5});
							}
						}
					})
			 },function(index){
			    layer.close(index);
		     });
	      }
		
	   	if("${msg}"!=""){
		   	layer.alert("${msg}", {icon: 6});
	  	}
		//compareListValue(document.getElementById('mz'),'${student.mz}');
	</script>
</body>
</html>